from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
testCase="DBshop020_编辑商品评价"
text1="下次还是会回购"
text2="谢谢亲的支持和好评"
# 订单号
rootPath=get_pro_rootpath()
orderID=readFile(rootPath+r'\public\order1.txt')
# 1.登录前台界面，点击我的订单，已完成订单，点击尚未评价，编写商品评价“下次还是会回购”，点击“点击提交”按钮。
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_partial_link_text("交易完成").click()
time.sleep(1)
firefox.find_element_by_xpath("//input[@name='search_order_sn']").send_keys(orderID)
firefox.find_element_by_xpath("//button[text()='搜索']").click()
time.sleep(1)
firefox.find_element_by_partial_link_text("尚未评价").click()
time.sleep(1)
firefox.find_element_by_id("comment_body").send_keys(text1)
time.sleep(1)
firefox.find_element_by_xpath("//button").click()
time.sleep(1)
firefox.quit()
# 2.回到后台界面，点击“编辑查看”，点击“评价回复”，评价回复“谢谢亲的支持和好评”，点击“回复商品评价”按钮。评价成功。
firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"商品管理","商品评价")
firefox.find_element_by_link_text("编辑查看").click()
time.sleep(1)
firefox.find_element_by_link_text("评价回复").click()
time.sleep(1)
firefox.find_element_by_id("reply_comment_content").send_keys(text2)
time.sleep(1)
firefox.find_element_by_xpath("//button[text()='回复商品评价']").click()
time.sleep(3)
string=firefox.find_element_by_xpath("//body").text
# print(string)
l="回复内容："
r="\n"
text=reGetString(string,l,r)
# print("hhhhhhhhhhhhhhhhhhhhhhhhhh",text)
if text==text2:
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()